#include <iostream>
#include <vector>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;

typedef unsigned long long ull;
const int N = 1505;
char s[N];
int n,m;

class stringhash{
    public:
        const ull base1 = 29,base2 = 31,mod1 = 1000000007,mod2 = 1000000009;
        ull h1[N],h2[N];
        ull inv1[N],inv2[N];

        inline void init(const char *s){
            int len = strlen(s+1);
            inv1[0] = 1;
            for(int k=1;k<=len;k++){
                h1[k] = (h1[k-1]*base1%mod1+(s[k]-'0'+1))%mod1;
                inv1[k] = inv1[k-1]*base1%mod1;
            }
            inv2[0] = 1;
            for(int k=1;k<=len;k++){
                h2[k] = (h2[k-1]*base2%mod2+(s[k]-'0'+1))%mod2;
                inv2[k] = inv2[k-1]*base2%mod2;
            }
        }

        inline ull h(int l,int r){
            ull key1 = (h1[r]-h1[l-1]*inv1[r-l+1]%mod1+mod1)%mod1;
            ull key2 = (h2[r]-h2[l-1]*inv2[r-l+1]%mod2+mod2)%mod2;
            return key1*mod1+key2;
        }

        inline ull h(string s){
            ull key1 = 0,key2 = 0;
            for(char c:s)
                key1 = (key1*base1%mod1+(c-'0'+1))%mod1;
            for(char c:s)
                key2 = (key2*base2%mod2+(c-'0'+1))%mod2;
            return key1*mod1+key2;
        }
};

namespace sub_1_7{
    vector<pair<string,int>> qus;
    stringhash h;
    __float128 solve(){
        __float128 ans = 0;
        int cnt = 0;
        h.init(s);
        for(auto [c,v]:qus){
            auto hs = h.h(c);
            for(int k=1;k<=n-(int)c.size()+1;k++)
                if(h.h(k,k+c.size()-1)==hs)
                    ans += log2l(v),cnt++;
        }
        return cnt?ans/cnt:0;
    }
    __float128 magic = 0;
    string ans;
    vector<int> q;
    void dfs(int u){
        if(u==(int)q.size()){
            auto w = solve();
            if(w>magic){
                magic = w;
                ans.clear();
                for(int k=1;k<=n;k++)
                    ans += s[k];
            }
            return;
        }
        for(int k='0';k<='9';k++){
            s[q[u]] = k;
            dfs(u+1);
        }
    }
    int main(){
        qus.resize(m);
        for(int k=0;k<m;k++)
            cin >> qus[k].first >> qus[k].second;
        for(int k=1;k<=n;k++)
            if(s[k]=='.')
                q.push_back(k);
        dfs(0);
        cout << ans;
        return 0;
    }
}

int main(){
    freopen("magic.in","r",stdin);
    freopen("magic.out","w",stdout);
    cin >> n >> m >> (s+1);
    int cnt = 0;
    for(int k=1;k<=n;k++)
        if(s[k]=='.')
            cnt++;
    return sub_1_7::main();
}